package cn.newstrength.liguowei.step;

import cn.newstrength.wtdf.plugin.service.RedisService;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.exception.PAIException;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;

import java.util.Map;

public class RedisStep implements OperationStep {

	@Override
	public int excute(Operation oper) throws PAIException {
		/*
		 * 数据预处理
		 */
		DataContext dc = oper.getContext();
		String key = dc.getElementValue("key");
		/*
		 * 获取 Redis 助手
		 */
		RedisService redis = oper.getBean("redisService", RedisService.class);
		redis.put(key, "Hi redis!");
		/*
		 * 回传数据
		 */
		dc.setTranStepResult(redis.getString(key));
		return 0;
	}

	@Override
	public int init(Map<String, String> arg0) {
		return 0;
	}
}
